package br.com.fatecpg.view;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import br.com.fatecpg.util.IPUtil;
import java.util.Vector;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
 * @author Edison
 */
public class IPDetails extends MIDlet implements CommandListener {

    private boolean midletPaused = false;
    //<editor-fold defaultstate="collapsed" desc=" Generated Fields ">//GEN-BEGIN:|fields|0|
    private Form formCalcular;
    private TextField ipTextField;
    private TextField bitsMascaraTextField;
    private Form formDetalhes;
    private StringItem detalhesMascaraStringItem;
    private StringItem detahesNetIDStringItem;
    private StringItem detalhesBroadCastStringItem;
    private StringItem detalhesUltimoIPValidoStringItem;
    private StringItem detalhesIPStringItem;
    private StringItem detalhesPrimeiroIPValidoStringItem;
    private StringItem detalhesIPValidoStringItem;
    private StringItem detalhesIPPublicoPrivadoSringItem;
    private StringItem detalhesQtdIPValidosStringItem;
    private Form formImagem;
    private ImageItem imageItem;
    private Form formInfo;
    private StringItem stringItem;
    private StringItem stringItem1;
    private StringItem stringItem2;
    private Form formAjuda;
    private StringItem stringItem3;
    private StringItem stringItem4;
    private StringItem stringItem5;
    private Command calcularItemCommand;
    private Command backCommand;
    private Command detalhesBackCommand;
    private Command backCommand1;
    private Command Continuar;
    private Command exitCommand;
    private Command backCommand2;
    private Command itemCommand;
    private Command ajudaItemCommand;
    private Command backCommand3;
    private Image image;
    //</editor-fold>//GEN-END:|fields|0|

    /**
     * The IPDetails constructor.
     */
    public IPDetails() {
    }

    //<editor-fold defaultstate="collapsed" desc=" Generated Methods ">//GEN-BEGIN:|methods|0|
    //</editor-fold>//GEN-END:|methods|0|
    //<editor-fold defaultstate="collapsed" desc=" Generated Method: initialize ">//GEN-BEGIN:|0-initialize|0|0-preInitialize
    /**
     * Initilizes the application.
     * It is called only once when the MIDlet is started. The method is called before the <code>startMIDlet</code> method.
     */
    private void initialize() {//GEN-END:|0-initialize|0|0-preInitialize
        // write pre-initialize user code here
//GEN-LINE:|0-initialize|1|0-postInitialize
        // write post-initialize user code here
    }//GEN-BEGIN:|0-initialize|2|
    //</editor-fold>//GEN-END:|0-initialize|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: startMIDlet ">//GEN-BEGIN:|3-startMIDlet|0|3-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Started point.
     */
    public void startMIDlet() {//GEN-END:|3-startMIDlet|0|3-preAction
        // write pre-action user code here
        switchDisplayable(null, getFormImagem());//GEN-LINE:|3-startMIDlet|1|3-postAction
        // write post-action user code here
    }//GEN-BEGIN:|3-startMIDlet|2|
    //</editor-fold>//GEN-END:|3-startMIDlet|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: resumeMIDlet ">//GEN-BEGIN:|4-resumeMIDlet|0|4-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Resumed point.
     */
    public void resumeMIDlet() {//GEN-END:|4-resumeMIDlet|0|4-preAction
        // write pre-action user code here
//GEN-LINE:|4-resumeMIDlet|1|4-postAction
        // write post-action user code here
    }//GEN-BEGIN:|4-resumeMIDlet|2|
    //</editor-fold>//GEN-END:|4-resumeMIDlet|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: switchDisplayable ">//GEN-BEGIN:|5-switchDisplayable|0|5-preSwitch
    /**
     * Switches a current displayable in a display. The <code>display</code> instance is taken from <code>getDisplay</code> method. This method is used by all actions in the design for switching displayable.
     * @param alert the Alert which is temporarily set to the display; if <code>null</code>, then <code>nextDisplayable</code> is set immediately
     * @param nextDisplayable the Displayable to be set
     */
    public void switchDisplayable(Alert alert, Displayable nextDisplayable) {//GEN-END:|5-switchDisplayable|0|5-preSwitch
        // write pre-switch user code here
        Display display = getDisplay();//GEN-BEGIN:|5-switchDisplayable|1|5-postSwitch
        if (alert == null) {
            display.setCurrent(nextDisplayable);
        } else {
            display.setCurrent(alert, nextDisplayable);
        }//GEN-END:|5-switchDisplayable|1|5-postSwitch
        // write post-switch user code here
    }//GEN-BEGIN:|5-switchDisplayable|2|
    //</editor-fold>//GEN-END:|5-switchDisplayable|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: commandAction for Displayables ">//GEN-BEGIN:|7-commandAction|0|7-preCommandAction
    /**
     * Called by a system to indicated that a command has been invoked on a particular displayable.
     * @param command the Command that was invoked
     * @param displayable the Displayable where the command was invoked
     */
    public void commandAction(Command command, Displayable displayable) {//GEN-END:|7-commandAction|0|7-preCommandAction
        // write pre-action user code here
        if (displayable == formAjuda) {//GEN-BEGIN:|7-commandAction|1|65-preAction
            if (command == backCommand3) {//GEN-END:|7-commandAction|1|65-preAction
                // write pre-action user code here
                switchDisplayable(null, getFormCalcular());//GEN-LINE:|7-commandAction|2|65-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|3|62-preAction
        } else if (displayable == formCalcular) {
            if (command == ajudaItemCommand) {//GEN-END:|7-commandAction|3|62-preAction
                // write pre-action user code here
                switchDisplayable(null, getFormAjuda());//GEN-LINE:|7-commandAction|4|62-postAction
                // write post-action user code here
            } else if (command == backCommand) {//GEN-LINE:|7-commandAction|5|20-preAction
                // write pre-action user code here
                switchDisplayable(null, getFormInfo());//GEN-LINE:|7-commandAction|6|20-postAction
                // write post-action user code here
            } else if (command == calcularItemCommand) {//GEN-LINE:|7-commandAction|7|18-preAction

                switchDisplayable(null, getFormDetalhes());//GEN-LINE:|7-commandAction|8|18-postAction
                String bits = bitsMascaraTextField.getString();
                String ip = ipTextField.getString();
                String valido = IPUtil.validarDados(ip, bits, getDisplay());
                System.out.println("###################### retorno: " + valido);
                if (valido == null) {
                    int bitsMascara = Integer.parseInt(bitsMascaraTextField.getString());
                    String mascara = IPUtil.getMascara(bitsMascara);
                    String netID = IPUtil.getNetID(ip, mascara);
                    String primeiroIPValido = IPUtil.getPrimeiroIPValido(netID);
                    String broadcast = IPUtil.getBroadCast(mascara, netID);
                    String ultimoIPValido = IPUtil.getUltimoIPValido(broadcast);
                    String ipValido = IPUtil.validarIP(ip, primeiroIPValido, ultimoIPValido);
                    String ipPublicoPrivado = IPUtil.getPublicoPrivado(ip);
                    int qtdIPsValidos = IPUtil.getQuantidadeIPValidoSubRede(netID, broadcast);
                    detalhesIPStringItem.setText(ip + " \\ " + bitsMascara);
                    detalhesMascaraStringItem.setText(mascara);
                    detahesNetIDStringItem.setText(netID);
                    detalhesPrimeiroIPValidoStringItem.setText(primeiroIPValido);
                    detalhesBroadCastStringItem.setText(broadcast);
                    detalhesUltimoIPValidoStringItem.setText(ultimoIPValido);
                    detalhesIPValidoStringItem.setText(ipValido);
                    detalhesIPPublicoPrivadoSringItem.setText(ipPublicoPrivado);
                    detalhesQtdIPValidosStringItem.setText("" + qtdIPsValidos);
                }else{
                    switchDisplayable(null, getFormCalcular());
                    Alert erro = new Alert("Erro");
                    erro.setString(valido);
                    erro.setTimeout(3000);
                    getDisplay().setCurrent(erro);
                    limparCampos();
                }

            }//GEN-BEGIN:|7-commandAction|9|28-preAction
        } else if (displayable == formDetalhes) {
            if (command == detalhesBackCommand) {//GEN-END:|7-commandAction|9|28-preAction
                // write pre-action user code here
                switchDisplayable(null, getFormCalcular());//GEN-LINE:|7-commandAction|10|28-postAction
                limparCampos();
            }//GEN-BEGIN:|7-commandAction|11|43-preAction
        } else if (displayable == formImagem) {
            if (command == Continuar) {//GEN-END:|7-commandAction|11|43-preAction
                // write pre-action user code here
                switchDisplayable(null, getFormInfo());//GEN-LINE:|7-commandAction|12|43-postAction
                // write post-action user code here
            } else if (command == exitCommand) {//GEN-LINE:|7-commandAction|13|48-preAction
                // write pre-action user code here
                exitMIDlet();//GEN-LINE:|7-commandAction|14|48-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|15|53-preAction
        } else if (displayable == formInfo) {
            if (command == backCommand2) {//GEN-END:|7-commandAction|15|53-preAction
                // write pre-action user code here
                switchDisplayable(null, getFormImagem());//GEN-LINE:|7-commandAction|16|53-postAction
                // write post-action user code here
            } else if (command == itemCommand) {//GEN-LINE:|7-commandAction|17|55-preAction
                // write pre-action user code here
                switchDisplayable(null, getFormCalcular());//GEN-LINE:|7-commandAction|18|55-postAction
                // write post-action user code here
            }//GEN-BEGIN:|7-commandAction|19|7-postCommandAction
        }//GEN-END:|7-commandAction|19|7-postCommandAction
        // write post-action user code here
    }//GEN-BEGIN:|7-commandAction|20|
    //</editor-fold>//GEN-END:|7-commandAction|20|
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: formCalcular ">//GEN-BEGIN:|14-getter|0|14-preInit
    /**
     * Returns an initiliazed instance of formCalcular component.
     * @return the initialized component instance
     */
    public Form getFormCalcular() {
        if (formCalcular == null) {//GEN-END:|14-getter|0|14-preInit
            // write pre-init user code here
            formCalcular = new Form("IP Details: Entre com os dados", new Item[] { getIpTextField(), getBitsMascaraTextField() });//GEN-BEGIN:|14-getter|1|14-postInit
            formCalcular.addCommand(getCalcularItemCommand());
            formCalcular.addCommand(getBackCommand());
            formCalcular.addCommand(getAjudaItemCommand());
            formCalcular.setCommandListener(this);//GEN-END:|14-getter|1|14-postInit
            // write post-init user code here
        }//GEN-BEGIN:|14-getter|2|
        return formCalcular;
    }
    //</editor-fold>//GEN-END:|14-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: ipTextField ">//GEN-BEGIN:|15-getter|0|15-preInit
    /**
     * Returns an initiliazed instance of ipTextField component.
     * @return the initialized component instance
     */
    public TextField getIpTextField() {
        if (ipTextField == null) {//GEN-END:|15-getter|0|15-preInit
            // write pre-init user code here
            ipTextField = new TextField("IP", "", 32, TextField.ANY);//GEN-LINE:|15-getter|1|15-postInit
            // write post-init user code here
        }//GEN-BEGIN:|15-getter|2|
        return ipTextField;
    }
    //</editor-fold>//GEN-END:|15-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: bitsMascaraTextField ">//GEN-BEGIN:|16-getter|0|16-preInit
    /**
     * Returns an initiliazed instance of bitsMascaraTextField component.
     * @return the initialized component instance
     */
    public TextField getBitsMascaraTextField() {
        if (bitsMascaraTextField == null) {//GEN-END:|16-getter|0|16-preInit
            // write pre-init user code here
            bitsMascaraTextField = new TextField("Bits da Mascara", "", 32, TextField.ANY);//GEN-LINE:|16-getter|1|16-postInit
            // write post-init user code here
        }//GEN-BEGIN:|16-getter|2|
        return bitsMascaraTextField;
    }
    //</editor-fold>//GEN-END:|16-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: calcularItemCommand ">//GEN-BEGIN:|17-getter|0|17-preInit
    /**
     * Returns an initiliazed instance of calcularItemCommand component.
     * @return the initialized component instance
     */
    public Command getCalcularItemCommand() {
        if (calcularItemCommand == null) {//GEN-END:|17-getter|0|17-preInit
            // write pre-init user code here
            calcularItemCommand = new Command("Verificar Detalhes", Command.ITEM, 0);//GEN-LINE:|17-getter|1|17-postInit
            // write post-init user code here
        }//GEN-BEGIN:|17-getter|2|
        return calcularItemCommand;
    }
    //</editor-fold>//GEN-END:|17-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand ">//GEN-BEGIN:|19-getter|0|19-preInit
    /**
     * Returns an initiliazed instance of backCommand component.
     * @return the initialized component instance
     */
    public Command getBackCommand() {
        if (backCommand == null) {//GEN-END:|19-getter|0|19-preInit
            // write pre-init user code here
            backCommand = new Command("Voltar", Command.BACK, 0);//GEN-LINE:|19-getter|1|19-postInit
            // write post-init user code here
        }//GEN-BEGIN:|19-getter|2|
        return backCommand;
    }
    //</editor-fold>//GEN-END:|19-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: formDetalhes ">//GEN-BEGIN:|25-getter|0|25-preInit
    /**
     * Returns an initiliazed instance of formDetalhes component.
     * @return the initialized component instance
     */
    public Form getFormDetalhes() {
        if (formDetalhes == null) {//GEN-END:|25-getter|0|25-preInit
            // write pre-init user code here
            formDetalhes = new Form("IP Details: Detalhes da subrede", new Item[] { getDetalhesIPStringItem(), getDetalhesIPValidoStringItem(), getDetalhesIPPublicoPrivadoSringItem(), getDetalhesMascaraStringItem(), getDetahesNetIDStringItem(), getDetalhesPrimeiroIPValidoStringItem(), getDetalhesUltimoIPValidoStringItem(), getDetalhesBroadCastStringItem(), getDetalhesQtdIPValidosStringItem() });//GEN-BEGIN:|25-getter|1|25-postInit
            formDetalhes.addCommand(getDetalhesBackCommand());
            formDetalhes.setCommandListener(this);//GEN-END:|25-getter|1|25-postInit
            // write post-init user code here
        }//GEN-BEGIN:|25-getter|2|
        return formDetalhes;
    }
    //</editor-fold>//GEN-END:|25-getter|2|
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: detalhesMascaraStringItem ">//GEN-BEGIN:|29-getter|0|29-preInit
    /**
     * Returns an initiliazed instance of detalhesMascaraStringItem component.
     * @return the initialized component instance
     */
    public StringItem getDetalhesMascaraStringItem() {
        if (detalhesMascaraStringItem == null) {//GEN-END:|29-getter|0|29-preInit
            // write pre-init user code here
            detalhesMascaraStringItem = new StringItem("Mascara:", "");//GEN-LINE:|29-getter|1|29-postInit
            // write post-init user code here
        }//GEN-BEGIN:|29-getter|2|
        return detalhesMascaraStringItem;
    }
    //</editor-fold>//GEN-END:|29-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: detalhesBackCommand ">//GEN-BEGIN:|27-getter|0|27-preInit
    /**
     * Returns an initiliazed instance of detalhesBackCommand component.
     * @return the initialized component instance
     */
    public Command getDetalhesBackCommand() {
        if (detalhesBackCommand == null) {//GEN-END:|27-getter|0|27-preInit
            // write pre-init user code here
            detalhesBackCommand = new Command("Voltar", Command.BACK, 0);//GEN-LINE:|27-getter|1|27-postInit
            // write post-init user code here
        }//GEN-BEGIN:|27-getter|2|
        return detalhesBackCommand;
    }
    //</editor-fold>//GEN-END:|27-getter|2|
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: detahesNetIDStringItem ">//GEN-BEGIN:|31-getter|0|31-preInit
    /**
     * Returns an initiliazed instance of detahesNetIDStringItem component.
     * @return the initialized component instance
     */
    public StringItem getDetahesNetIDStringItem() {
        if (detahesNetIDStringItem == null) {//GEN-END:|31-getter|0|31-preInit
            // write pre-init user code here
            detahesNetIDStringItem = new StringItem("NetID:", "");//GEN-LINE:|31-getter|1|31-postInit
            // write post-init user code here
        }//GEN-BEGIN:|31-getter|2|
        return detahesNetIDStringItem;
    }
    //</editor-fold>//GEN-END:|31-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: detalhesIPStringItem ">//GEN-BEGIN:|32-getter|0|32-preInit
    /**
     * Returns an initiliazed instance of detalhesIPStringItem component.
     * @return the initialized component instance
     */
    public StringItem getDetalhesIPStringItem() {
        if (detalhesIPStringItem == null) {//GEN-END:|32-getter|0|32-preInit
            // write pre-init user code here
            detalhesIPStringItem = new StringItem("IP:", "");//GEN-LINE:|32-getter|1|32-postInit
            // write post-init user code here
        }//GEN-BEGIN:|32-getter|2|
        return detalhesIPStringItem;
    }
    //</editor-fold>//GEN-END:|32-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: detalhesPrimeiroIPValidoStringItem ">//GEN-BEGIN:|33-getter|0|33-preInit
    /**
     * Returns an initiliazed instance of detalhesPrimeiroIPValidoStringItem component.
     * @return the initialized component instance
     */
    public StringItem getDetalhesPrimeiroIPValidoStringItem() {
        if (detalhesPrimeiroIPValidoStringItem == null) {//GEN-END:|33-getter|0|33-preInit
            // write pre-init user code here
            detalhesPrimeiroIPValidoStringItem = new StringItem("1\u00BA IP V\u00E1lido:", "");//GEN-LINE:|33-getter|1|33-postInit
            // write post-init user code here
        }//GEN-BEGIN:|33-getter|2|
        return detalhesPrimeiroIPValidoStringItem;
    }
    //</editor-fold>//GEN-END:|33-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: detalhesBroadCastStringItem ">//GEN-BEGIN:|34-getter|0|34-preInit
    /**
     * Returns an initiliazed instance of detalhesBroadCastStringItem component.
     * @return the initialized component instance
     */
    public StringItem getDetalhesBroadCastStringItem() {
        if (detalhesBroadCastStringItem == null) {//GEN-END:|34-getter|0|34-preInit
            // write pre-init user code here
            detalhesBroadCastStringItem = new StringItem("Broadcast:", "");//GEN-LINE:|34-getter|1|34-postInit
            // write post-init user code here
        }//GEN-BEGIN:|34-getter|2|
        return detalhesBroadCastStringItem;
    }
    //</editor-fold>//GEN-END:|34-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: detalhesUltimoIPValidoStringItem ">//GEN-BEGIN:|35-getter|0|35-preInit
    /**
     * Returns an initiliazed instance of detalhesUltimoIPValidoStringItem component.
     * @return the initialized component instance
     */
    public StringItem getDetalhesUltimoIPValidoStringItem() {
        if (detalhesUltimoIPValidoStringItem == null) {//GEN-END:|35-getter|0|35-preInit
            // write pre-init user code here
            detalhesUltimoIPValidoStringItem = new StringItem("Ultimo IP V\u00E1lido:", "");//GEN-LINE:|35-getter|1|35-postInit
            // write post-init user code here
        }//GEN-BEGIN:|35-getter|2|
        return detalhesUltimoIPValidoStringItem;
    }
    //</editor-fold>//GEN-END:|35-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: detalhesIPValidoStringItem ">//GEN-BEGIN:|36-getter|0|36-preInit
    /**
     * Returns an initiliazed instance of detalhesIPValidoStringItem component.
     * @return the initialized component instance
     */
    public StringItem getDetalhesIPValidoStringItem() {
        if (detalhesIPValidoStringItem == null) {//GEN-END:|36-getter|0|36-preInit
            // write pre-init user code here
            detalhesIPValidoStringItem = new StringItem("IP V\u00E1lido: ", "");//GEN-LINE:|36-getter|1|36-postInit
            // write post-init user code here
        }//GEN-BEGIN:|36-getter|2|
        return detalhesIPValidoStringItem;
    }
    //</editor-fold>//GEN-END:|36-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: detalhesIPPublicoPrivadoSringItem ">//GEN-BEGIN:|37-getter|0|37-preInit
    /**
     * Returns an initiliazed instance of detalhesIPPublicoPrivadoSringItem component.
     * @return the initialized component instance
     */
    public StringItem getDetalhesIPPublicoPrivadoSringItem() {
        if (detalhesIPPublicoPrivadoSringItem == null) {//GEN-END:|37-getter|0|37-preInit
            // write pre-init user code here
            detalhesIPPublicoPrivadoSringItem = new StringItem("IP P\u00FAblico ou Privado:", "");//GEN-LINE:|37-getter|1|37-postInit
            // write post-init user code here
        }//GEN-BEGIN:|37-getter|2|
        return detalhesIPPublicoPrivadoSringItem;
    }
    //</editor-fold>//GEN-END:|37-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: detalhesQtdIPValidosStringItem ">//GEN-BEGIN:|38-getter|0|38-preInit
    /**
     * Returns an initiliazed instance of detalhesQtdIPValidosStringItem component.
     * @return the initialized component instance
     */
    public StringItem getDetalhesQtdIPValidosStringItem() {
        if (detalhesQtdIPValidosStringItem == null) {//GEN-END:|38-getter|0|38-preInit
            // write pre-init user code here
            detalhesQtdIPValidosStringItem = new StringItem("Quantidade de IP\'s v\u00E1lidos:", "");//GEN-LINE:|38-getter|1|38-postInit
            // write post-init user code here
        }//GEN-BEGIN:|38-getter|2|
        return detalhesQtdIPValidosStringItem;
    }
    //</editor-fold>//GEN-END:|38-getter|2|
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: formImagem ">//GEN-BEGIN:|39-getter|0|39-preInit
    /**
     * Returns an initiliazed instance of formImagem component.
     * @return the initialized component instance
     */
    public Form getFormImagem() {
        if (formImagem == null) {//GEN-END:|39-getter|0|39-preInit
            // write pre-init user code here
            formImagem = new Form("IP Details", new Item[] { getImageItem() });//GEN-BEGIN:|39-getter|1|39-postInit
            formImagem.addCommand(getContinuar());
            formImagem.addCommand(getExitCommand());
            formImagem.setCommandListener(this);//GEN-END:|39-getter|1|39-postInit
            // write post-init user code here
        }//GEN-BEGIN:|39-getter|2|
        return formImagem;
    }
    //</editor-fold>//GEN-END:|39-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: imageItem ">//GEN-BEGIN:|44-getter|0|44-preInit
    /**
     * Returns an initiliazed instance of imageItem component.
     * @return the initialized component instance
     */
    public ImageItem getImageItem() {
        if (imageItem == null) {//GEN-END:|44-getter|0|44-preInit
            // write pre-init user code here
            imageItem = new ImageItem("", getImage(), ImageItem.LAYOUT_DEFAULT, "<Imagem perdida>");//GEN-BEGIN:|44-getter|1|44-postInit
            imageItem.setPreferredSize(-1, -1);//GEN-END:|44-getter|1|44-postInit
//            Canvas canvas = new Canvas() {
//                protected void paint(Graphics g) {
//                    throw new UnsupportedOperationException("Not supported yet.");
//                }
//            };
//
//            imageItem.setPreferredSize(canvas.getWidth() , canvas.getHeight());

        }//GEN-BEGIN:|44-getter|2|
        return imageItem;
    }
    //</editor-fold>//GEN-END:|44-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand1 ">//GEN-BEGIN:|40-getter|0|40-preInit
    /**
     * Returns an initiliazed instance of backCommand1 component.
     * @return the initialized component instance
     */
    public Command getBackCommand1() {
        if (backCommand1 == null) {//GEN-END:|40-getter|0|40-preInit
            // write pre-init user code here
            backCommand1 = new Command("Voltar", Command.BACK, 0);//GEN-LINE:|40-getter|1|40-postInit
            // write post-init user code here
        }//GEN-BEGIN:|40-getter|2|
        return backCommand1;
    }
    //</editor-fold>//GEN-END:|40-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: Continuar ">//GEN-BEGIN:|42-getter|0|42-preInit
    /**
     * Returns an initiliazed instance of Continuar component.
     * @return the initialized component instance
     */
    public Command getContinuar() {
        if (Continuar == null) {//GEN-END:|42-getter|0|42-preInit
            // write pre-init user code here
            Continuar = new Command("Continuar", Command.ITEM, 0);//GEN-LINE:|42-getter|1|42-postInit
            // write post-init user code here
        }//GEN-BEGIN:|42-getter|2|
        return Continuar;
    }
    //</editor-fold>//GEN-END:|42-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: image ">//GEN-BEGIN:|45-getter|0|45-preInit
    /**
     * Returns an initiliazed instance of image component.
     * @return the initialized component instance
     */
    public Image getImage() {
        if (image == null) {//GEN-END:|45-getter|0|45-preInit
            // write pre-init user code here
            try {//GEN-BEGIN:|45-getter|1|45-@java.io.IOException
                image = Image.createImage("/br/com/fatecpg/imagens/banner.jpg");
            } catch (java.io.IOException e) {//GEN-END:|45-getter|1|45-@java.io.IOException
                e.printStackTrace();
            }//GEN-LINE:|45-getter|2|45-postInit
            // write post-init user code here
        }//GEN-BEGIN:|45-getter|3|
        return image;
    }
    //</editor-fold>//GEN-END:|45-getter|3|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: exitCommand ">//GEN-BEGIN:|47-getter|0|47-preInit
    /**
     * Returns an initiliazed instance of exitCommand component.
     * @return the initialized component instance
     */
    public Command getExitCommand() {
        if (exitCommand == null) {//GEN-END:|47-getter|0|47-preInit
            // write pre-init user code here
            exitCommand = new Command("Sair", Command.EXIT, 0);//GEN-LINE:|47-getter|1|47-postInit
            // write post-init user code here
        }//GEN-BEGIN:|47-getter|2|
        return exitCommand;
    }
    //</editor-fold>//GEN-END:|47-getter|2|
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: formInfo ">//GEN-BEGIN:|51-getter|0|51-preInit
    /**
     * Returns an initiliazed instance of formInfo component.
     * @return the initialized component instance
     */
    public Form getFormInfo() {
        if (formInfo == null) {//GEN-END:|51-getter|0|51-preInit
            // write pre-init user code here
            formInfo = new Form("IP Details: Informa\u00E7\u00F5es", new Item[] { getStringItem(), getStringItem1(), getStringItem2() });//GEN-BEGIN:|51-getter|1|51-postInit
            formInfo.addCommand(getBackCommand2());
            formInfo.addCommand(getItemCommand());
            formInfo.setCommandListener(this);//GEN-END:|51-getter|1|51-postInit
            // write post-init user code here
        }//GEN-BEGIN:|51-getter|2|
        return formInfo;
    }
    //</editor-fold>//GEN-END:|51-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem ">//GEN-BEGIN:|56-getter|0|56-preInit
    /**
     * Returns an initiliazed instance of stringItem component.
     * @return the initialized component instance
     */
    public StringItem getStringItem() {
        if (stringItem == null) {//GEN-END:|56-getter|0|56-preInit
            // write pre-init user code here
            stringItem = new StringItem("Sobre o Aplicativo:", "Este aplicativo foi desenvolvido como projeto da disciplina \'Programa\u00E7\u00E3o para Dispositivos Moveis\' do curso de An\u00E1lise e Desenvolvimento de Sistemas na Faculdade de Tecnologia de Praia Grande.");//GEN-LINE:|56-getter|1|56-postInit
            // write post-init user code here
        }//GEN-BEGIN:|56-getter|2|
        return stringItem;
    }
    //</editor-fold>//GEN-END:|56-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem1 ">//GEN-BEGIN:|57-getter|0|57-preInit
    /**
     * Returns an initiliazed instance of stringItem1 component.
     * @return the initialized component instance
     */
    public StringItem getStringItem1() {
        if (stringItem1 == null) {//GEN-END:|57-getter|0|57-preInit
            // write pre-init user code here
            stringItem1 = new StringItem("Autor:", "Edison Luiz Gon\u00E7alves Junior");//GEN-LINE:|57-getter|1|57-postInit
            // write post-init user code here
        }//GEN-BEGIN:|57-getter|2|
        return stringItem1;
    }
    //</editor-fold>//GEN-END:|57-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem2 ">//GEN-BEGIN:|58-getter|0|58-preInit
    /**
     * Returns an initiliazed instance of stringItem2 component.
     * @return the initialized component instance
     */
    public StringItem getStringItem2() {
        if (stringItem2 == null) {//GEN-END:|58-getter|0|58-preInit
            // write pre-init user code here
            stringItem2 = new StringItem("Professor:", "Ricardo Pupo Larguesa");//GEN-LINE:|58-getter|1|58-postInit
            // write post-init user code here
        }//GEN-BEGIN:|58-getter|2|
        return stringItem2;
    }
    //</editor-fold>//GEN-END:|58-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand2 ">//GEN-BEGIN:|52-getter|0|52-preInit
    /**
     * Returns an initiliazed instance of backCommand2 component.
     * @return the initialized component instance
     */
    public Command getBackCommand2() {
        if (backCommand2 == null) {//GEN-END:|52-getter|0|52-preInit
            // write pre-init user code here
            backCommand2 = new Command("Voltar", Command.BACK, 0);//GEN-LINE:|52-getter|1|52-postInit
            // write post-init user code here
        }//GEN-BEGIN:|52-getter|2|
        return backCommand2;
    }
    //</editor-fold>//GEN-END:|52-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: itemCommand ">//GEN-BEGIN:|54-getter|0|54-preInit
    /**
     * Returns an initiliazed instance of itemCommand component.
     * @return the initialized component instance
     */
    public Command getItemCommand() {
        if (itemCommand == null) {//GEN-END:|54-getter|0|54-preInit
            // write pre-init user code here
            itemCommand = new Command("Continuar", Command.ITEM, 0);//GEN-LINE:|54-getter|1|54-postInit
            // write post-init user code here
        }//GEN-BEGIN:|54-getter|2|
        return itemCommand;
    }
    //</editor-fold>//GEN-END:|54-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: ajudaItemCommand ">//GEN-BEGIN:|61-getter|0|61-preInit
    /**
     * Returns an initiliazed instance of ajudaItemCommand component.
     * @return the initialized component instance
     */
    public Command getAjudaItemCommand() {
        if (ajudaItemCommand == null) {//GEN-END:|61-getter|0|61-preInit
            // write pre-init user code here
            ajudaItemCommand = new Command("Ajuda", Command.ITEM, 0);//GEN-LINE:|61-getter|1|61-postInit
            // write post-init user code here
        }//GEN-BEGIN:|61-getter|2|
        return ajudaItemCommand;
    }
    //</editor-fold>//GEN-END:|61-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: formAjuda ">//GEN-BEGIN:|63-getter|0|63-preInit
    /**
     * Returns an initiliazed instance of formAjuda component.
     * @return the initialized component instance
     */
    public Form getFormAjuda() {
        if (formAjuda == null) {//GEN-END:|63-getter|0|63-preInit
            // write pre-init user code here
            formAjuda = new Form("IP Details: Ajuda", new Item[] { getStringItem3(), getStringItem4(), getStringItem5() });//GEN-BEGIN:|63-getter|1|63-postInit
            formAjuda.addCommand(getBackCommand3());
            formAjuda.setCommandListener(this);//GEN-END:|63-getter|1|63-postInit
            // write post-init user code here
        }//GEN-BEGIN:|63-getter|2|
        return formAjuda;
    }
    //</editor-fold>//GEN-END:|63-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: backCommand3 ">//GEN-BEGIN:|64-getter|0|64-preInit
    /**
     * Returns an initiliazed instance of backCommand3 component.
     * @return the initialized component instance
     */
    public Command getBackCommand3() {
        if (backCommand3 == null) {//GEN-END:|64-getter|0|64-preInit
            // write pre-init user code here
            backCommand3 = new Command("Voltar", Command.BACK, 0);//GEN-LINE:|64-getter|1|64-postInit
            // write post-init user code here
        }//GEN-BEGIN:|64-getter|2|
        return backCommand3;
    }
    //</editor-fold>//GEN-END:|64-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem3 ">//GEN-BEGIN:|68-getter|0|68-preInit
    /**
     * Returns an initiliazed instance of stringItem3 component.
     * @return the initialized component instance
     */
    public StringItem getStringItem3() {
        if (stringItem3 == null) {//GEN-END:|68-getter|0|68-preInit
            // write pre-init user code here
            stringItem3 = new StringItem("IP:", "Entre com o IP no formato X.X.X.X por exemplo (10.0.0.1). Os Ips s\u00E3o dividos em 4 n\u00FAmeros e cada valor pode ser no m\u00E1ximo 255(8 bits)");//GEN-LINE:|68-getter|1|68-postInit
            // write post-init user code here
        }//GEN-BEGIN:|68-getter|2|
        return stringItem3;
    }
    //</editor-fold>//GEN-END:|68-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem4 ">//GEN-BEGIN:|69-getter|0|69-preInit
    /**
     * Returns an initiliazed instance of stringItem4 component.
     * @return the initialized component instance
     */
    public StringItem getStringItem4() {
        if (stringItem4 == null) {//GEN-END:|69-getter|0|69-preInit
            // write pre-init user code here
            stringItem4 = new StringItem("Bits da Mascara:", "Entre com a quantidade de bits que a m\u00E1scara da suberede possui, esse valor pode ser no m\u00EDnimo 0 e no maximo 30");//GEN-LINE:|69-getter|1|69-postInit
            // write post-init user code here
        }//GEN-BEGIN:|69-getter|2|
        return stringItem4;
    }
    //</editor-fold>//GEN-END:|69-getter|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Getter: stringItem5 ">//GEN-BEGIN:|70-getter|0|70-preInit
    /**
     * Returns an initiliazed instance of stringItem5 component.
     * @return the initialized component instance
     */
    public StringItem getStringItem5() {
        if (stringItem5 == null) {//GEN-END:|70-getter|0|70-preInit
            // write pre-init user code here
            stringItem5 = new StringItem("Calculo:", "O Sistema vai mostrar em detalhes todos os dados da suberede com os valores fornecidos pelo usu\u00E1rio");//GEN-LINE:|70-getter|1|70-postInit
            // write post-init user code here
        }//GEN-BEGIN:|70-getter|2|
        return stringItem5;
    }
    //</editor-fold>//GEN-END:|70-getter|2|

    /**
     * Returns a display instance.
     * @return the display instance.
     */
    public Display getDisplay() {
        return Display.getDisplay(this);
    }

    /**
     * Exits MIDlet.
     */
    public void exitMIDlet() {
        switchDisplayable(null, null);
        destroyApp(true);
        notifyDestroyed();
    }

    /**
     * Called when MIDlet is started.
     * Checks whether the MIDlet have been already started and initialize/starts or resumes the MIDlet.
     */
    public void startApp() {
        if (midletPaused) {
            resumeMIDlet();
        } else {
            initialize();
            startMIDlet();
        }
        midletPaused = false;
    }

    /**
     * Called when MIDlet is paused.
     */
    public void pauseApp() {
        midletPaused = true;
    }

    /**
     * Called to signal the MIDlet to terminate.
     * @param unconditional if true, then the MIDlet has to be unconditionally terminated and all resources has to be released.
     */
    public void destroyApp(boolean unconditional) {
    }
    public void limparCampos(){
        ipTextField.setString("");
        bitsMascaraTextField.setString("");
    }
}
